package base.container;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class TestIterator {
	public static void main(String[] args) {
		Collection c = new HashSet();
		c.add(new Name("f1","l1"));
		c.add(new Name("f2","l2"));
		c.add(new Name("f3","l3"));
		Iterator i = c.iterator();
		
		while(i.hasNext()){
			Name n = (Name)i.next();
			System.out.println(n.GetFistname());
		}
		
		//方法2，使用泛型
		
		Collection<Name> collection = new HashSet<Name>();
		collection.add(new Name("f4","l4"));
		collection.add(new Name("f5","l5"));
		collection.add(new Name("f6","l6"));
		//collection.add("hello");
		Iterator<Name> iterator = collection.iterator();
		
		while(iterator.hasNext()){
			Name name = iterator.next();
			System.out.println(name.LastName);
		}
		
	}
}
